package java44th.group.service.catalog;

import com.sun.org.apache.xml.internal.resolver.CatalogManager;
import java44th.group.bean.po.MarketCategory;
import java44th.group.bean.po.MarketCategoryExample;
import java44th.group.bean.wx.vo.catalog.CurrentVo;
import java44th.group.bean.wx.vo.catalog.IndexVo;
import java44th.group.mapper.MarketCategoryMapper;
import java44th.group.service.admin.category.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Aurhor: 徐云飞
 * @DATE: 2022/10/14 22:11
 * @Description:
 * @Version 1.0
 */
@Service
@Transactional
public class CatalogServiceImpl implements CatalogService {
    @Autowired
    MarketCategoryMapper categoryMapper;

    @Override
    public CurrentVo current(Integer id) {

        MarketCategory marketCategory = categoryMapper.selectByPrimaryKey(id);
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andPidEqualTo(id);
        List<MarketCategory> marketCategories = categoryMapper.selectByExample(marketCategoryExample);

        return new CurrentVo(marketCategory, marketCategories);

    }

    @Override
    public IndexVo index() {
        MarketCategoryExample marketCategoryExample1 = new MarketCategoryExample();
        marketCategoryExample1.createCriteria().andLevelEqualTo("L1");

        List<MarketCategory> marketCategories1 = categoryMapper.selectByExample(marketCategoryExample1);
        MarketCategory marketCategory1 = marketCategories1.get(0);
        Integer id = marketCategory1.getId();
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andPidEqualTo(id);
        List<MarketCategory> marketCategories = categoryMapper.selectByExample(marketCategoryExample);



        IndexVo indexVo = new IndexVo(marketCategories1, marketCategory1, marketCategories);
        return indexVo;


    }
}
